import os
import json

input_folder = "/home/jxy/jxy"
txt_files = [f for f in os.listdir(input_folder) if f.endswith(".txt")]

# 按文件名排序
txt_files = sorted(txt_files)

json_list = []

for txt_file in txt_files:
    file_path = os.path.join(input_folder, txt_file)
    
    # 打开文件并读取内容
    with open(file_path, 'r') as file:
        file_content = file.read()
    
    # 将单引号的属性名替换为双引号
    file_content = file_content.replace("'", "\"")
    
    # 添加逗号分隔符
    json_list.append(file_content + ",")

# 移除最后一个逗号
if json_list:
    json_list[-1] = json_list[-1][:-1]

# 组装 JSON 数组
json_str = '[' + ''.join(json_list) + ']'

output_file = "/home/jxy/program/hoi2/600HOI-600HOI_no_object-add_seg_only_instance-max_adapt-dynamic_threshold_add_weight_23-black_add_correlation_hoi/output/frame_pred_tags.json"

# 将 JSON 写入文件
with open(output_file, 'w') as json_file:
    json_file.write(json_str)

print(f"JSON文件 '{output_file}' 已保存成功。")
